#include "helicopterSkin.h"
#include "topHelixes.h"
#include "backHelixes.h"
#include "footHelicopter.h"
#include "../framework.h"

Vertexf HelicopterSkin::vertices[] = { 	Vertexf(50.0f,14.0f),Vertexf(95.0f,14.0f),
										Vertexf(95.0f,-10.0f),Vertexf(90.0f,-10.0f),
										Vertexf(80.0f,1.0f),Vertexf(50.0f,1.0f),
										Vertexf(0,50.0f),//Vertice de circulo
										Vertexf(-19.0f,0),Vertexf(-8.0f,0),
										Vertexf(-8.0f,-10.0f),Vertexf(87.5,-8),Vertexf(84,-4),
										Vertexf(87.5,0),Vertexf(91,-4)};


HelicopterSkin::HelicopterSkin(	Rectangle rec)
	:	SceneObject(rec){
	this->objVertices.vertices = HelicopterSkin::vertices;
	this->objVertices.nVertices = nVertices;
	this->addObject(TopHelixes::name(),new TopHelixes(rec));
	this->addObject(BackHelixes::name(),new BackHelixes(rec));
	this->addObject(FootHelicopter::name(),new FootHelicopter(rec));
}

HelicopterSkin::~HelicopterSkin(){}

void HelicopterSkin::draw(){
	Framework& fr = Framework::instance();
    Colorf oldColor = fr.pipeline.getFillColor();
        fr.pipeline.pushMatrix();
            fr.pipeline.setFillColor(Colorf(0.3f,0.65f,0.3f));
            fr.pipeline.escale(0.4f,0.25f);
            fr.pipeline.draw(Pipeline::CIRCLES,&(vertices[6]),1);
        fr.pipeline.popMatrix();
        fr.pipeline.pushMatrix();
            fr.pipeline.escale(0.75f,0.75f);
            fr.pipeline.translate(-35,-5);
            fr.pipeline.draw(Pipeline::POLYGON,vertices,6);
        fr.pipeline.popMatrix();
        //Dibuja Rombo
        fr.pipeline.pushMatrix();
            fr.pipeline.translate(-49.0f,5);
            fr.pipeline.setFillColor(Colorf(.5f,0.45f,0.40f));
            fr.pipeline.draw(Pipeline::POLYGON,&(vertices[10]),4);
            fr.pipeline.setFillColor(oldColor);
        fr.pipeline.popMatrix();
        fr.pipeline.pushMatrix();
            fr.pipeline.translate(0,-15);
            (this->findObject(TopHelixes::name())).draw();
       // Dibuja helice trasera
        fr.pipeline.popMatrix();
        fr.pipeline.pushMatrix();
            fr.pipeline.translate(40,-8);
            (this->findObject(BackHelixes::name())).draw();
        fr.pipeline.popMatrix();
        //dibuja la ventana
        fr.pipeline.pushMatrix();
            fr.pipeline.translate(-1,0);
            fr.pipeline.setFillColor(Colorf(0.48f,0.79f,1.0f));
            fr.pipeline.draw(Pipeline::POLYGON,&(vertices[7]),3);
        fr.pipeline.popMatrix();
        fr.pipeline.setFillColor(oldColor);
        (this->findObject(FootHelicopter::name())).draw();
}

void HelicopterSkin::timeStep(){
    BackHelixes& backHelix = dynamic_cast<BackHelixes&>(this->findObject(BackHelixes::name()));
	TopHelixes& topHelix = dynamic_cast<TopHelixes&>(this->findObject(TopHelixes::name()));
	backHelix.timeStep();
	topHelix.timeStep();
}
